[qemu-dm] Add bounds checks to block device reads/writes.
authorChristian Limpach <Christian.Limpach@xensource.com>
Tue, 24 Apr 2007 16:02:09 +0000 (17:02 +0100)
committerChristian Limpach <Christian.Limpach@xensource.com>
Tue, 24 Apr 2007 16:02:09 +0000 (17:02 +0100)
Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
tools/ioemu/block.c

index 00444abb19f34a7516e609d68cc367f285fc5d75..34757f455709809b14b0df3446cc48baacb41cba 100644 (file)
@@ -420,6 +420,8 @@ int bdrv_read(BlockDriverState *bs, int64_t sector_num,
 
     if (!bs->inserted)
         return -1;
+    if (sector_num < 0)
+       return -1;
 
     while (nb_sectors > 0) {
         if (sector_num == 0 && bs->boot_sector_enabled) {
@@ -458,6 +460,8 @@ int bdrv_write(BlockDriverState *bs, int64_t sector_num,
         return -1;
     if (bs->read_only)
         return -1;
+    if (sector_num < 0)
+       return -1;
     if (sector_num == 0 && bs->boot_sector_enabled && nb_sectors > 0) {
         memcpy(bs->boot_sector_data, buf, 512);   
     }